package com.asion.vmovie.activities;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.asion.vmovie.ui.MVPModel.BaseModel;
import com.asion.vmovie.ui.MVPPresenter.BasePresenter;
import com.asion.vmovie.utils.LoadingDailog;
import com.asion.vmovie.utils.Tutil;

import butterknife.ButterKnife;

/**
 * Created by asion on 16-10-17.
 */

public abstract class BaseActivity<T extends BasePresenter, E extends BaseModel>  extends AppCompatActivity {

    public T mPresenter;
    public E mModel;
    public Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(getLayoutId());
        ButterKnife.bind(this);
        mContext = this;
        mPresenter = Tutil.getT(this, 0);
        mModel= Tutil.getT(this,1);
        if(mPresenter!=null){
            mPresenter.context=this;
        }
        this.initPresenter();
        this.initView();
    }

    /*********************子类实现*****************************/
    //获取布局文件
    public abstract int getLayoutId();
    //简单页面无需mvp就不用管此方法即可,完美兼容各种实际场景的变通
    public abstract void initPresenter();
    //初始化view
    public abstract void initView();

    public void startProgressDialog() {
        LoadingDailog.showDialogForLoading(this);
    }

    /**
     * 开启加载进度条
     *
     * @param msg
     */
    public void startProgressDialog(String msg) {
        LoadingDailog.showDialogForLoading(this, msg, true);
    }

    /**
     * 停止加载进度条
     */
    public void stopProgressDialog() {
        LoadingDailog.cancelDialogForLoading();
    }
}
